package findertestproject;

import java.awt.Dimension;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.WindowConstants;
import ro.sergiu.finder.ui.button.ButtonFinder;
import ro.sergiu.finder.ui.button.listeners.SelectionListener;

/**
 *
 * @author toporjinschi
 */
public class Main extends javax.swing.JFrame {

    public Main() {
        initComponents();
        buttonFinder2.setFinderModel(new Customizer(getMsSQLConnection()));
        buttonFinder2.addSelectionListener(new SelectionListener<User>() {

            @Override
            public void perform(List<User> selection) {
                if (selection == null) {
                    return;
                }
                System.out.println(selection.get(0));
            }
        });
    }

    /**
     * Create This method is called from within the constructor to initialize
     * the form. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonFinder2 = new ButtonFinder();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLocationByPlatform(true);

        buttonFinder2.setText("buttonFinder2");

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonFinder2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(168, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonFinder2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(157, Short.MAX_VALUE))
        );

        setSize(new Dimension(274, 230));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    public static void main(String args[]) throws Exception {
//        JDialog.setDefaultLookAndFeelDecorated(true);
//        JFrame.setDefaultLookAndFeelDecorated(true);
//        UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ButtonFinder buttonFinder2;
    // End of variables declaration//GEN-END:variables

    private Connection getMySQLConnection() {
        Connection connect = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            // Setup the connection with the DB
            connect = DriverManager.getConnection("jdbc:mysql://localhost/bardb?user=root&password=");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        return connect;
    }
    private Connection getMsSQLConnection() {
        Connection connect = null;
        try {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            // Setup the connection with the DB
            connect = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.50.139:1433/CLIX2013.2.1.RC","CLIX2013.2.1.RC","imc_clix");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        return connect;
    }
}
